<?php

namespace Home\Controller;

use Think\Controller;
use Org\Util\Juhe;
/**
 * 进货单控制器
 * @author zhangwei
 */
class RejectController extends HomeController {
    public function reject() {
         $userid = session('userid');   
         $timestamp=time()-2*24*3600;
         $sql="select a.city,a.street,a.shopName,a.realName,a.phone,d.name,d.id,d.quantity,b.createDate,c.orderid,b.lastupdate from gr_buyers a,gr_order b,gr_order_goods c,gr_product d where a.id = $userid and b.orderid = c.orderid and c.pid = d.id and b.uid = a.id and b.lastupdate > $timestamp and  (b.status=2000 OR b.status=3000)";
        // $sql="select a.city,a.street,a.shopName,a.realName,a.phone,d.name,d.quantity,c.orderid,c.lastupdate from gr_buyers a,gr_order b,gr_order_goods c,gr_product d where a.openid = $userid and"."b.status = 3000";
//          $sql="select * from gr_buyers where id =2";
         $res=D('buyers')->query($sql);
         $addr=$res[0]['city'].$res[0]['street'].$res[0]['shopname'];
         foreach($res as $key => $value){
             $value['createdate']= date('m-d',$value['createdate']);
             $res[$key]['xddate']=$value['createdate'];
         }
      
          $this->rejectinfo=$res;
          $this->assign("realname",$res[0]['realname']);
          $this->assign("phone",$res[0]['phone']);
          $this->assign("addr",$addr);
          $this->display();
          
          
    }
     public function saveReject() {
        $userid = session('userid');   
        $map = array('uid' => $userid);
        if (IS_POST) {
                // 上传文件 
                $setting = array(
                    'mimes' => '', //允许上传的文件MiMe类型
                    'maxSize' => 3 * 1024 * 1024, //上传的文件大小限制 (0-不做限制)
                    'exts' => 'jpg,gif,png,jpeg', //允许上传的文件后缀
                );
                /* 调用文件上传组件上传文件 */
                /*                 * 修改开始* */
                $pic_driver = C('PICTURE_UPLOAD_DRIVER');
                $upload = new \Think\Upload($setting, C('PICTURE_UPLOAD_DRIVER'), C("UPLOAD_{$pic_driver}_CONFIG"));
                $info = $upload->upload();
                if (!$info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                } else {// 上传成功}
                }
                    $reject_order="TD".time()."".rand(0, 10);
                    $user_name=$_POST['username'];
                    $user_tel=$_POST['usertel'];
                    $user_addr=$_POST['useraddr'];
                    $describe = $_POST['describe'];
                    $data = array('uid' => $userid,'orderid' => $reject_order, 'create_time'=>time(),'describe' => $describe,'user_name'=>$user_name,'user_tel'=>$user_tel,'user_addr'=>$user_addr,);
                    $reszsm=M('reject_order')->add($data);
                    if($reszsm){
                        $goods_length=count($_POST['good_name']);
                        $data2['orderid']=$reject_order;
                        for($i=0;$i<$goods_length;$i++){
                            $data2['pname']=$_POST['good_name'][$i];
                            $data2['old_order']=$_POST['good_order'][$i];
                            $data2['num']=$_POST['good_num'][$i];
                            $data2['pic']=$info[$i]["url"];
                           M('reject_order_goods')->add($data2);
                        }
                        
                         $this->display();
                    }
                //}
                
//               $this->display('Registration/regSuccess');       
            }else{
                
            }
           
        
        
    }
    
//    
////    
//  public function registration() { 
//        $userid = session('userid');
//        $isReged=M('gwzjl_reg')->query('select id from gr_gwzjl_reg where openid="'.$userid.'" ');
//        if(count($isReged)==0){
//            //$workstype = $_GET['workstype'];$userid = session('userid');
//            //echo session("useropenid");
//            //session('worsktype',1);
//            //$this->assign('workstype', $workstype);
//            $this->display();
//        }else{
//            //报名成功
//            $isRegSuccess=M('gwzjl_reg')->query('select * from gr_gwzjl_reg where openid="'.OPENID1.'" and status=1 limit 1');
//            //echo $isRegSuccess[0]['regstatus'];
//            
//            if($isRegSuccess[0]['regstatus']==0){
//                //报名成功，尚未审核
//                $this->display('Registration/regSuccess');
//            }elseif($isRegSuccess[0]['regstatus']==1){
//                //报名成功，审核通过
//                 $this->redirect('home/Me/me');
//            }else{
//                //报名成功，审核未通过
//                 $this->redirect('Registration/regFailed');
//            }       
//        }
//        
//    }
//    public function regSuccess(){
//        $this->display();
//    }
//    public function regFailed(){
//        $this->display();
//    }
//    public function saveRegistration() {
//        $userid =OPENID1;        
//        //$userid = 1234567894;
//        $map = array('openid' => $userid);
//        $isReg = M('gwzjl_reg')->where($map)->select();
//        if (count($isReg)!=0) {
//            //存在，则不能报名
//            
//        } else {
//            //不存在，能报名
//            if (IS_POST) {
//                // 上传文件 
//                $setting = array(
//                    'mimes' => '', //允许上传的文件MiMe类型
//                    'maxSize' => 3 * 1024 * 1024, //上传的文件大小限制 (0-不做限制)
//                    'exts' => 'jpg,gif,png,jpeg', //允许上传的文件后缀
//                );
//                /* 调用文件上传组件上传文件 */
//                /*                 * 修改开始* */
//                $pic_driver = C('PICTURE_UPLOAD_DRIVER');
//                $upload = new \Think\Upload($setting, C('PICTURE_UPLOAD_DRIVER'), C("UPLOAD_{$pic_driver}_CONFIG"));
//                $info = $upload->upload();
//
//                //if (!$info) {// 上传错误提示错误信息
//                    //$this->error($upload->getError());
//                //} else {// 上传成功
//                    $username = $_POST['username'];
//                    $usertel = $_POST['usertel'];
//                    $worksname = $_POST['worksname'];
//                    //$workspicture=$_POST['workspicture'];
//                    $worksmaterials = $_POST['worksmaterials'];
//                    $worksfeel = $_POST['worksfeel'];
//                    $workseffect = $_POST['workseffect'];
//                    $workstype = $_POST['workstype'];
//
//                    $data = array('openid' => $userid, 'username' => $username, 'userphone' => $usertel, 'worksname' => $worksname, 'workstype' => $workstype, 'pic1' => $info["pic1"]["url"], 'pic2' => $info["pic2"]["url"], 'pic3' => $info["pic3"]["url"], 'worksmaterial' => $worksmaterials, 'workstaste' => $worksfeel, 'workseffect' => $workseffect, 'createAt' => NOW_TIME);
//                    $reszsm=M('gwzjl_reg')->add($data);
//                //}
//                    if($reszsm){
//                        $this->success('报名成功，正在为您创建优惠券帐号...','https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx0e5dece83e52048b&redirect_uri=http://wxshop.guoran100.com&response_type=code&scope=snsapi_userinfo&state=1&connect_redirect=1#wechat_redirect',1);
//                    }
////               $this->display('Registration/regSuccess');       
//            }
//            //$this->display();
//        }
//        
//    }

}
